A comparison expression is part of an expression where one left-hand value is compared with one or more other right-hand values. While the a regular
expression contains left-hand value, comparison operator and right values, the comparison expression leaves out the left-hand value out.
case() and compare select() are two common functions which utilize comparison expressions.
Attention: Extra arentheses are required when specifying individual values, multiple values spearated with commas, ranges, and when using following comparison operators in front: = and <>. The reason is
that with out parentheses, the comparison tries to hijack all further parameters separated with commas as their own right-hand values to compare, too.
No extra parentheses are required when the comparison expression is in the last function parameter or is the only one function parameter.
No extraparentheses are required if the comparison expression begins with following operators: <, <=, >, <=, ==, and !=.
No extra parentheses are required if the comparison expression is provided in a string value.
p[] = { 2, 3, 5, 7, 10, 11, 13, 17, 23, 31, 37, A, a, Hello };
for all parameters( p[], var[] )
{
result[] = compare select( var[], other,
(11,37), is 11 or 37, // Parentheses required if no operator put in front
==13, thirteen,
(=+a), 1st letter in alphabet, // Parentheses required with = and <>
('H*'), Begins with H,
>15, greater than 15,
(3..5,10), "is one of 3..5, 10" );
print(var[],": ", result[]," / ");
// Demonstrate the same with comparison expressions in strings. Note the colons used in front.
c[] = '(3..5,10)';
result[] = compare select( var[], other,
:str(11)+",37", is 11 or 37, // Expression returning a string
:'==13', thirteen, // Softquoted string: No difference to quoted string
:'=+a', 1st letter in alphabet,
:"'H*'", Begins with H, // See note below !
:">15", greater than 15,
:c[], "is one of 3..5, 10" ); // Referring to a variable
echo(result[]);
}
// Note :"'H*'" with nested quotation marks: Expression inside requires a single quotation mark to
// let the comparison expression support wildcard symbols.
2: other / other
3: is one of 3..5, 10 / is one of 3..5, 10
5: is one of 3..5, 10 / is one of 3..5, 10
7: other / other
10: is one of 3..5, 10 / is one of 3..5, 10
11: is 11 or 37 / is 11 or 37
13: thirteen / thirteen
17: greater than 15 / greater than 15
23: greater than 15 / greater than 15
31: greater than 15 / greater than 15
37: is 11 or 37 / is 11 or 37
A: 1st letter in alphabet / 1st letter in alphabet
a: 1st letter in alphabet / 1st letter in alphabet
Hello: Begins with H / Begins with H